package com.longge;

import java.util.HashMap;

/**
 * @创建人 xinglongge
 * @创建时间 2021/11/23
 * @描述
 */
public class CanConstruct {
    public boolean canConstruct(String ransomNote, String magazine) {
        char[] rChars = ransomNote.toCharArray();
        char[] mChars = magazine.toCharArray();
        HashMap<Character, Integer> mMap = new HashMap<>();
        for (char mChar : mChars) {
            mMap.put(mChar, mMap.getOrDefault(mChar, 0) + 1);
        }
        for (char rChar : rChars) {
            Integer i = mMap.get(rChar);
            if (i == null || i == 0) return false;
            mMap.put(rChar, --i);
        }

        return true;
    }
}
